package com.mjh.manager;

import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.mjh.bean.Category;
import com.mjh.config.GlobalConfig;
import com.mjh.dao.CategoryConfigDAO;

public class CategoryConfigManager {

	public static Logger log = Logger.getLogger(CategoryConfigManager.class);
	
	private CategoryConfigDAO dao = new CategoryConfigDAO();
	
	public void addCategory(String categoryName){
		dao.addCategory(categoryName);
		GlobalConfig.setCategoryMap(dao.listAllCategory());
	}
	
	public void addSubCategory(String parentId, String subCategoryName){
		dao.addSubCategory(parentId, subCategoryName);
		GlobalConfig.setCategoryMap(dao.listAllCategory());
	}
	
	public void updateCategory(String id, String name){
		dao.updateCategory(id, name);
		GlobalConfig.setCategoryMap(dao.listAllCategory());
	}

	public void removeCategory(String id){
		dao.delCategory(id);
		GlobalConfig.setCategoryMap(dao.listAllCategory());
	}
	
	public ArrayList<Category> listCategory(){
		return dao.listAllCategory();
	}
}
